#include <iostream>
#include <vector>

/**
 * PAT A 1091 Acute Stroke
 * This solution adopts union-find algorithm, which is more efficient and easier
 * to code compared with the commonly-used BFS method.
 */

struct Pixel {
    bool stroke;
    int volume;
    int parent;

    Pixel(bool stroke, int index) : stroke(stroke), volume(0), parent(index) {}
};

int depth, height, width;

inline int index(int d, int h, int w) {
    return d * (height * width) + h * width + w;
}

std::vector<Pixel> pixels;

int find(int idx) {
    Pixel &pix = pixels[idx];
    if (pix.parent != idx) pix.parent = find(pix.parent);
    return pix.parent;
}

void Union(int i1, int i2) {
    int r1 = find(i1);
    int r2 = find(i2);
    pixels[r2].parent = r1;
}

void connect(int idx, int d, int h, int w) {
    if (d > 0) {
        int backIdx = idx - height * width;
        Pixel &backPix = pixels[backIdx];
        if (backPix.stroke) Union(backIdx, idx);
    }
    if (h > 0) {
        int upIdx = idx - width;
        Pixel &upPix = pixels[upIdx];
        if (upPix.stroke) Union(upIdx, idx);
    }
    if (w > 0) {
        int leftIdx = idx - 1;
        Pixel &leftPix = pixels[leftIdx];
        if (leftPix.stroke) Union(leftIdx, idx);
    }
}

int main() {
    // Read image and connect pixels
    int thresh;
    scanf("%d %d %d %d", &height, &width, &depth, &thresh);
    pixels.reserve(height * width * depth);
    for (int d = 0; d < depth; d++) {
        for (int h = 0; h < height; h++) {
            for (int w = 0; w < width; w++) {
                int stroke;
                scanf("%d", &stroke);
                int idx = pixels.size();
                pixels.push_back(Pixel(stroke, idx));
                if (stroke) connect(idx, d, h, w);
            }
        }
    }

    // Count volume of each core
    for (int i = 0; i < pixels.size(); i++)
        if (pixels[i].stroke) pixels[find(i)].volume++;

    // Count total volume
    int total = 0;
    for (int i = 0; i < pixels.size(); i++) {
        Pixel &pix = pixels[i];
        if (!pix.stroke || pix.parent != i) continue;
        if (pix.volume < thresh) continue;
        total += pix.volume;
    }
    printf("%d\n", total);

    return 0;
}